const { saveRole, deleteRole, getRoleList } = require('@/service/user/role');
const Response = require('@/utils/response')

class RoleController {
  async saveRole(ctx) { 
    const params = ctx.request.body;
    try {
      const result = await saveRole(params);
      return Response.success(ctx, result);
    } catch (error) {
        return Response.error(ctx, error.message);
    }
  }
  async deleteRole(ctx) { 
    const {id} = ctx.request.body;
    try {
      if(!id) return Response.error(ctx, '参数错误',400);
      const result = await deleteRole(id);
      return Response.success(ctx, result);
    } catch (error) {
        return Response.error(ctx, error.message);
    }
  }
  async getRoleList(ctx) { 
    const params = ctx.request.body;
    try {
        const result = await getRoleList(params);
        return Response.success(ctx, result);
    } catch (error) {
      return Response.error(ctx, error.message || '获取角色列表失败', 500);
    }
  }
}

// 导出 RoleController 类
module.exports = new RoleController();
